package jaloveast1k.site.com.google.sites.utils;

import java.util.HashMap;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Paint;

public class BitmapHolder {
	private static BitmapHolder sSingleton;
	private HashMap<Integer, Bitmap> mMaps = new HashMap<Integer, Bitmap>();
	private Resources mRes;
	private Paint mDefPaint;
	
	public static final int CELL_WIDTH = 70;
	public static final int CELL_HEIGHT = 60;
	public static final int CELL_HEIGHT_VERTICAL = 30;
	
	private BitmapHolder() {
		
	}
	
	public static BitmapHolder getInstance() 
	{
        if (sSingleton == null) 
        {
            synchronized (BitmapHolder.class) 
            {
                if (sSingleton == null) 
                {
                    sSingleton = new BitmapHolder();
                }
            }
        }
        return sSingleton;
    }
	
	public void regContext(Context cont) {
		mRes = cont.getResources();
	}
	
	public Bitmap getBitmap(int id)
	{
		if (mMaps.get(id) != null) {
			return mMaps.get(id);
		}
		else {
//			Bitmap bmp = BitmapFactory.decodeResource(mRes, id);
			Bitmap bmp = BitmapFactory.decodeStream(mRes.openRawResource(id));
			
			if (bmp != null)
			{
				mMaps.put(id, bmp);
			}
			return bmp;
		}
	}
	
	public Paint getDefaultPaint()
	{
		if (mDefPaint == null)
		{
			synchronized (BitmapHolder.class) 
            {
                if (mDefPaint == null) 
                {
                    mDefPaint = new Paint();
                }
            }
		}
		
		return mDefPaint;
	}
}
